package com.ruoyi.inventory.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.inventory.domain.*;
import com.ruoyi.inventory.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.inventory.service.IInventoryManagementService;

/**
 * 存货管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-13
 */
@Service
public class InventoryManagementServiceImpl implements IInventoryManagementService 
{
    @Autowired
    private InventoryManagementMapper inventoryManagementMapper;

    /**
     * 存货类型
     */
    @Autowired
    private InventoryTypeMapper inventoryTypeMapper;

    /**
     * 存货分类
     */
    @Autowired
    private InventoryCategoryMapper inventoryCategoryMapper;

    /**
     * 计价方式
     */
    @Autowired
    private PricingMethodMapper pricingMethodMapper;

    /**
     * 单位
     */
    @Autowired
    private InventoryUnitMapper inventoryUnitMapper;

    /**
     * 查询存货管理
     * 
     * @param id 存货管理主键
     * @return 存货管理
     */
    @Override
    public InventoryManagement selectInventoryManagementById(Long id)
    {
        return inventoryManagementMapper.selectInventoryManagementById(id);
    }

    /**
     * 查询存货管理列表
     * 
     * @param inventoryManagement 存货管理
     * @return 存货管理
     */
    @Override
    public List<InventoryManagement> selectInventoryManagementList(InventoryManagement inventoryManagement)
    {
        return inventoryManagementMapper.selectInventoryManagementList(inventoryManagement);
    }

    /**
     * 新增存货管理
     * 
     * @param inventoryManagement 存货管理
     * @return 结果
     */
    @Override
    public int insertInventoryManagement(InventoryManagement inventoryManagement)
    {
        inventoryManagement.setCreateTime(DateUtils.getNowDate());
        return inventoryManagementMapper.insertInventoryManagement(inventoryManagement);
    }

    /**
     * 修改存货管理
     * 
     * @param inventoryManagement 存货管理
     * @return 结果
     */
    @Override
    public int updateInventoryManagement(InventoryManagement inventoryManagement)
    {
        inventoryManagement.setUpdateTime(DateUtils.getNowDate());
        return inventoryManagementMapper.updateInventoryManagement(inventoryManagement);
    }

    /**
     * 批量删除存货管理
     * 
     * @param ids 需要删除的存货管理主键
     * @return 结果
     */
    @Override
    public int deleteInventoryManagementByIds(Long[] ids)
    {
        return inventoryManagementMapper.deleteInventoryManagementByIds(ids);
    }

    /**
     * 删除存货管理信息
     * 
     * @param id 存货管理主键
     * @return 结果
     */
    @Override
    public int deleteInventoryManagementById(Long id)
    {
        return inventoryManagementMapper.deleteInventoryManagementById(id);
    }

    /**
     * 使用线程查询所有下拉框数据
     * @return
     */
    @Override
    public Map<String, List<?>> getSelectAllData() {

        // 存货类型
        List<InventoryType> inventoryTypes = inventoryTypeMapper.selectList(null);

        // 存货分类
        List<InventoryCategory> inventoryCategories = inventoryCategoryMapper.selectList(null);

        // 计价方式
        List<PricingMethod> pricingMethods = pricingMethodMapper.selectList(null);

        // 单位
        List<InventoryUnit> inventoryUnits = inventoryUnitMapper.selectList(null);

        HashMap<String, List<?>> stringListHashMap = new HashMap<>();
        stringListHashMap.put("inventoryTypeList", inventoryTypes);
        stringListHashMap.put("inventoryCategoryList", inventoryCategories);
        stringListHashMap.put("pricingMethodList", pricingMethods);
        stringListHashMap.put("inventoryUnitList", inventoryUnits);

        return stringListHashMap;
    }
}
